import requests

# 测试基本地址
BASE_URL = "http://192.168.110.35:9688/shibie/aiApi/getCameraInfo"

def test_success():
    """ 测试正常请求 """
    params = {
        "cameraName": "测试摄像头",
        "videoName": "测试视频",
        "state": 1
    }
    response = requests.get(BASE_URL, params=params)
    
    # 验证状态码和返回数据
    assert response.status_code == 200
    data = response.json()
    assert data["code"] == 200
    assert data["data"]["state"] == 1

def test_missing_params():
    """ 测试缺少参数 """
    # 测试缺少cameraName
    response = requests.get(BASE_URL, params={
        "videoName": "测试视频",
        "state": 1
    })
    assert response.status_code == 400
    assert "cameraName" in response.json()["message"]

    # 测试缺少videoName
    response = requests.get(BASE_URL, params={
        "cameraName": "测试摄像头",
        "state": 1
    })
    assert response.status_code == 400
    assert "videoName" in response.json()["message"]

def test_invalid_state():
    """ 测试错误的状态值 """
    response = requests.get(BASE_URL, params={
        "cameraName": "测试摄像头",
        "videoName": "测试视频",
        "state": 2  # 非法状态
    })
    assert response.status_code == 400
    assert "Invalid state" in response.json()["message"]

if __name__ == "__main__":
    test_success()
    test_missing_params()
    test_invalid_state()
    print("所有基础测试通过！")